import os
import sys
import re
from matplotlib import pyplot as plt



class bcolors:
    HEADER = '\033[95m'
    OKBLUE = '\033[94m'
    OKGREEN = '\033[92m'
    WARNING = '\033[93m'
    FAIL = '\033[91m'
    ENDC = '\033[0m'
    BOLD = '\033[1m'
    UNDERLINE = '\033[4m'


fps = re.compile('Protocol:(.*):(.*)')


fn = sys.argv[1]

lines = open(fn).readlines()
fpss = []

num = 1
total = 1
xv = {}
nv = {}
for l in lines:
    ret = fps.findall(l)
    if len(ret) > 0:
       
        #print ret[0][0]
        pid = ret[0][0]
        size = ret[0][1]
        if pid not in xv:
            xv[pid] = 0
            nv[pid] = 0
        xv[pid] += int(size)
        nv[pid] += 1

#xv = nv


rows = []    
for p in xv:
    rows.append([p, xv[p]])

def cmp(a, b):
    if a[1] > b[1]:
        return -1
    elif a[1] < b[1]:
        return 1
    else:
        return 0
rows.sort(cmp=cmp)

l = len(rows)
width = 1.0/l

n = 0
sizes = []

ind = []
for r in rows:
    print r
    sizes.append(r[1])
    ind.append(n)
    n += 1

plt.bar(ind, sizes)  



plt.show()
